<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class SettingRequest extends Request
{
    public function authorize()
    {
        return true;
    }
    public function rules()
    {
       $editRules=[
           'id' =>'required|numeric',
           'name'=>'required',
           'variable'=>'required|alpha_dash',
           'value'=>'required',
            'sort'=>'required|numeric',
           'system'=>'required|boolean',
       ];
        $createRules = [
            'name'=>'required',
            'variable'=>'required|alpha_dash',
            'value'=>'required',
            'sort'=>'required|numeric',
            'system'=>'required|boolean',
        ];
        $data = Request::all();
        if($data['formType'] == 'edit'){
            return $editRules;
        }
        if($data['formType'] == 'create')
        {
            return $createRules;
        }
    }
    public function attributes()
    {
        $attributes = array(
            'name'=>'系统参数名称',
            'variable'=>'英文名',
            'sort'=>'排序',
            'system'=>'是否系统变量',
        );
    }
    public function messages()
    {
        $messages = [
            'required'=>':attribute为必填选项',
            'numeric'=>':attribute必须为数字',
            'alpha_dash'=>':attribute必须为字母he数字',
            'system.boolean'=>':attribute必须为是、不是中的一种',
        ];
        return $messages;
    }
}